package com.operate.api.operate.recommend;

import cn.dev33.satoken.annotation.SaCheckLogin;
import com.github.pagehelper.PageInfo;
import com.operate.api.app.info.domain.vo.*;
import com.operate.api.app.info.service.IAppCompanyService;
import com.operate.api.base.*;
import com.operate.api.operate.banner.service.IBannerService;
import com.operate.api.operate.user.domain.vo.UserUpdateVO;
import com.operate.util.BindingResultUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

@Api( tags = ApiIndex.RecommendController)
@RequestMapping(value = "/api/operate/recommend")
@RestController
public class RecommendController {


    @Autowired
    private IAppCompanyService companyService;

    @ApiOperation(value = "查询推荐制作方集合")
    @GetMapping(value = "/list")
    public R<RestPage<List<RecommendCompanyVO>>> company_list(
            @ApiParam(value = "查询参数") @ModelAttribute RecommendCompanySearchVO searchVO) {
        List<RecommendCompanyVO> list = companyService.getCompanyList(searchVO);
        RestPage restPage = new RestPage(new PageInfo(list), list);
        return new R(restPage);
    }



    @ApiOperation(value = "修改推荐信息")
    @PostMapping(value = "/update")
    @SaCheckLogin
    public R update(@ApiParam(value = "修改参数") @Valid @RequestBody RecommendCompanyUpdateVO updateVO, BindingResult bindingResult) {
        R result= BindingResultUtil.BindingResult(bindingResult);
        if(result.getCode()== Constants.SYS_SUCCESS){
            companyService.updateRecommend(updateVO);
        }
        return result;
    }



    @ApiOperation(value = "批量推荐信息")
    @PostMapping(value = "/batch_recommend")
    @SaCheckLogin
    public R batch_recommend(@ApiParam(value = "修改参数") @Valid @RequestBody IDsEntity iDsEntity, BindingResult bindingResult) {
        R result= BindingResultUtil.BindingResult(bindingResult);
        if(result.getCode()== Constants.SYS_SUCCESS){
            companyService.batchRecommend(iDsEntity);
        }
        return result;
    }


}